package com.cqjtu.email;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2016/11/26 0026.
 */
public class MailAdapter extends ArrayAdapter<MailContent> {

    private int resoureId;
    public MailAdapter(Context context, int resource, List<MailContent> objects) {
        super(context, resource, objects);
        resoureId = resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MailContent mail = getItem(position);
        View view ;
        ViewHolder viewHolder;
        if(convertView==null){
            view = LayoutInflater.from(getContext()).inflate(resoureId,null);
            viewHolder = new ViewHolder();
            viewHolder.subject = (TextView) view.findViewById(R.id.id_mailsubject);
            viewHolder.sender = (TextView) view.findViewById(R.id.id_mailsender);
            viewHolder.time = (TextView) view.findViewById(R.id.id_mailtime);
            view.setTag(viewHolder);
        }else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.subject.setText(mail.getSubject()+"");
        viewHolder.sender.setText(mail.getSender()+"");
        viewHolder.time.setText(mail.getTime()+"");

        return view;

    }
    class ViewHolder{
        TextView subject;
        TextView sender;
        TextView time;
    }
}
